# -*- coding: utf-8 -*-
"""
@project: AutoTesting_pulsar
@author: chenhh
@file: Session.py
@ide: PyCharm
@time: 2021/1/25
封装获取cookie方法
"""

import requests
import base64


from Common import Log
from Config import Config


class Session:
    def __init__(self):
        self.config = Config.Config()
        self.log = Log.MyLog()

    def get_session(self):
        """
        获取session
        :param env: 环境变量
        :return:
        """
        headers = {
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Safari/537.36",
            "Content-Type": "application/json"
        }
        try:
            login_url = self.config.test_url + '/api/user/login'
            a = self.config.login_user
            b = self.config.login_password
            param = {
                    "account": a,
                    "password": b
                }
            session_debug = requests.session()
            response = session_debug.post(login_url, param)
            #print(response.cookies)
            self.log.info('cookies: %s' % response.cookies.get_dict())
            return response.cookies.get_dict()

        except Exception as e:
            print(e)
            return ()

'''
if __name__ == '__main__':
     ss = Session()
     cookie = ss.get_session()
     ss1 = requests.get( 'https://bigdata-test.mypaas.com.cn/api/modeling/data_quality/monitor/list?status=&sorts=&keyword=&page=1&page_size=10',cookies=cookie)
     print(ss1)
'''